package com.caiyi.financial.nirvana.sms.controller;


import com.caiyi.financial.nirvana.sms.entity.SmsWhiteList;
import com.caiyi.financial.nirvana.sms.querybean.QueryMsgBean;
import com.caiyi.financial.nirvana.sms.service.SmsWhiteListService;
import com.youyu.common.api.Result;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

/**
 * 白名单管理
 */
@Api(description = "白名单管理接口")
@RequestMapping("sms/white")
@RestController
@CrossOrigin
public class SmsWhiteListController {

    @Autowired
    private SmsWhiteListService smsWhiteListService;

    @ApiOperation(value = "新增白名单", notes = "新增白名单")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "phone", value = "白名单手机号码", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "account", value = "账户", required = true, dataType = "String", paramType = "query"),
    })
    @PostMapping(value = "/addSmsWhiteList")
    public Result addSmsWhiteList(@RequestParam String phone, @RequestParam String account) {
        SmsWhiteList whiteList = new SmsWhiteList();
        whiteList.setPhone(phone);
        whiteList.setAccount(account);
        whiteList.setCreateTime(new Date());
        return Result.ok(smsWhiteListService.addSmsWhiteList(whiteList));
    }

    @ApiOperation(value = "删除白名单", notes = "删除白名单")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "phone", value = "白名单电话", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "account", value = "账户", required = true, dataType = "String", paramType = "query"),
    })
    @PostMapping(value = "/delSmsWhiteList")
    public Result delSmsWhiteList(@RequestParam String phone, @RequestParam String account) {
         smsWhiteListService.delSmsWhiteList(phone, account);
         return Result.ok();
    }


    @ApiOperation(value = "白名单列表查询", notes = "白名单列表查询")
    @PostMapping("/searchSmsWhiteList")
    public Result searchSmsWhiteList(@RequestBody @ApiParam(name = "bean", value = "白名单参数实体", required = true) QueryMsgBean bean) {
        return Result.ok(smsWhiteListService.searchSmsWhiteList(bean));

    }
}
